Imports System.Data.SqlClient

Public Class cls_poliza_

    Implements ICloneable

#Region "Variables ..."
    Private int_idpoliza As Integer = 0
    Private bit_precotizacion As Boolean = False
    Private bit_nueva As Boolean = False
    Private str_numero As String = ""
    Private str_numerorenueva As String = ""
    Private int_idpolizarenueva As Integer = 0
    Private bit_endoso As Boolean = False
    Private int_idpolizaendoso As Integer = 0
    Private bit_cambiounidad As Boolean = False
    Private dte_vigenciadesde As DateTime = New System.DateTime(Now.Year, 1, 1)
    Private dte_vigenciahasta As DateTime = New System.DateTime(Now.Year, 1, 1)
    Private int_idcliente As Integer = 0
    Private int_idriesgo As Integer = 0
    Private int_idproveedor As Integer = 0
    Private int_idmarca As Integer = 0
    Private int_idmodelo As Integer = 0
    Private str_año As String = ""
    Private str_patente As String = ""
    Private str_obs As String = ""
    Private str_observaciones As String = ""
    Private dbl_importe As Double = 0
    Private int_cuotas As Integer = 0
    Private dbl_importecuota As Double = 0
    Private int_idtipovencimiento As Integer = 0
    Private dte_primervencimiento As DateTime = New System.DateTime(Now.Year, 1, 1)
    Private int_idregistro As Integer = 0
    Private int_idvendedor As Integer = 0

    Private obj_polizarenueva As cls_poliza_ = Nothing
    Private obj_polizaendoso As cls_poliza_ = Nothing
    Private obj_cliente As cls_cliente_ = Nothing
    Private obj_riesgo As cls_riesgo_ = Nothing
    Private obj_proveedor As cls_proveedor_ = Nothing
    Private obj_marca As cls_marca_ = Nothing
    Private obj_modelo As cls_modelo_ = Nothing
    Private obj_tipovencimiento As cls_tipovencimiento_ = Nothing
    Private obj_registro As cls_registro_ = Nothing
    Private obj_vendedor As cls_vendedor_ = Nothing

    Private obj_cuota_ As cls_cuota_ = Nothing

    Private col_Items As Collections.Generic.List(Of cls_poliza_) = Nothing
#End Region

    Public Overrides Function ToString() As String
        Return numero
    End Function

#Region "Propiedades ..."
    ReadOnly Property This
        Get
            Return Me
        End Get
    End Property
    ReadOnly Property ThisDescripcion As String
        Get
            Return Me.ToString
        End Get
    End Property
    ReadOnly Property pKey
        Get
            Return idpoliza
        End Get
    End Property
    Property idpoliza() As Integer
        Get
            idpoliza = int_idpoliza
        End Get
        Set(ByVal value As Integer)
            int_idpoliza = value
        End Set
    End Property
    Property precotizacion() As Boolean
        Get
            precotizacion = bit_precotizacion
        End Get
        Set(ByVal value As Boolean)
            bit_precotizacion = value
        End Set
    End Property
    Property nueva() As Boolean
        Get
            nueva = bit_nueva
        End Get
        Set(ByVal value As Boolean)
            bit_nueva = value
        End Set
    End Property
    Property numero() As String
        Get
            numero = str_numero
        End Get
        Set(ByVal value As String)
            str_numero = value
        End Set
    End Property
    Property numerorenueva() As String
        Get
            numerorenueva = str_numerorenueva
        End Get
        Set(ByVal value As String)
            str_numerorenueva = value
        End Set
    End Property
    Property idpolizarenueva() As Integer
        Get
            idpolizarenueva = int_idpolizarenueva
        End Get
        Set(ByVal value As Integer)
            int_idpolizarenueva = value
        End Set
    End Property
    Property endoso() As Boolean
        Get
            endoso = bit_endoso
        End Get
        Set(ByVal value As Boolean)
            bit_endoso = value
        End Set
    End Property
    Property idpolizaendoso() As Integer
        Get
            idpolizaendoso = int_idpolizaendoso
        End Get
        Set(ByVal value As Integer)
            int_idpolizaendoso = value
        End Set
    End Property
    Property cambiounidad() As Boolean
        Get
            cambiounidad = bit_cambiounidad
        End Get
        Set(ByVal value As Boolean)
            bit_cambiounidad = value
        End Set
    End Property
    Property vigenciadesde() As DateTime
        Get
            vigenciadesde = dte_vigenciadesde
        End Get
        Set(ByVal value As DateTime)
            dte_vigenciadesde = value
        End Set
    End Property
    Property vigenciahasta() As DateTime
        Get
            vigenciahasta = dte_vigenciahasta
        End Get
        Set(ByVal value As DateTime)
            dte_vigenciahasta = value
        End Set
    End Property
    Property idcliente() As Integer
        Get
            idcliente = int_idcliente
        End Get
        Set(ByVal value As Integer)
            int_idcliente = value
        End Set
    End Property
    Property idriesgo() As Integer
        Get
            idriesgo = int_idriesgo
        End Get
        Set(ByVal value As Integer)
            int_idriesgo = value
        End Set
    End Property
    Property idproveedor() As Integer
        Get
            idproveedor = int_idproveedor
        End Get
        Set(ByVal value As Integer)
            int_idproveedor = value
        End Set
    End Property
    Property idmarca() As Integer
        Get
            idmarca = int_idmarca
        End Get
        Set(ByVal value As Integer)
            int_idmarca = value
        End Set
    End Property
    Property idmodelo() As Integer
        Get
            idmodelo = int_idmodelo
        End Get
        Set(ByVal value As Integer)
            int_idmodelo = value
        End Set
    End Property
    Property año() As String
        Get
            año = str_año
        End Get
        Set(ByVal value As String)
            str_año = value
        End Set
    End Property
    Property patente() As String
        Get
            patente = str_patente
        End Get
        Set(ByVal value As String)
            str_patente = value
        End Set
    End Property
    Property obs() As String
        Get
            obs = str_obs
        End Get
        Set(ByVal value As String)
            str_obs = value
        End Set
    End Property
    Property observaciones() As String
        Get
            observaciones = str_observaciones
        End Get
        Set(ByVal value As String)
            str_observaciones = value
        End Set
    End Property
    Property importe() As Double
        Get
            importe = dbl_importe
        End Get
        Set(ByVal value As Double)
            dbl_importe = value
        End Set
    End Property
    Property cuotas() As Integer
        Get
            cuotas = int_cuotas
        End Get
        Set(ByVal value As Integer)
            int_cuotas = value
        End Set
    End Property
    Property importecuota() As Double
        Get
            importecuota = dbl_importecuota
        End Get
        Set(ByVal value As Double)
            dbl_importecuota = value
        End Set
    End Property
    Property idtipovencimiento() As Integer
        Get
            idtipovencimiento = int_idtipovencimiento
        End Get
        Set(ByVal value As Integer)
            int_idtipovencimiento = value
        End Set
    End Property
    Property primervencimiento() As DateTime
        Get
            primervencimiento = dte_primervencimiento
        End Get
        Set(ByVal value As DateTime)
            dte_primervencimiento = value
        End Set
    End Property
    Property idregistro() As Integer
        Get
            idregistro = int_idregistro
        End Get
        Set(ByVal value As Integer)
            int_idregistro = value
        End Set
    End Property
    Property idvendedor() As Integer
        Get
            idvendedor = int_idvendedor
        End Get
        Set(ByVal value As Integer)
            int_idvendedor = value
        End Set
    End Property
    Property polizarenueva As cls_poliza_
        Get
            If IsNothing(obj_polizarenueva) Then
                obj_polizarenueva = New cls_poliza_
                If Not obj_polizarenueva.Buscar(idpolizarenueva) Then
                    obj_polizarenueva = Nothing
                End If
            End If
            polizarenueva = obj_polizarenueva
        End Get
        Set(ByVal value As cls_poliza_)
            obj_polizarenueva = value
        End Set
    End Property
    Property polizaendoso As cls_poliza_
        Get
            If IsNothing(obj_polizaendoso) Then
                obj_polizaendoso = New cls_poliza_
                If Not obj_polizaendoso.Buscar(idpolizaendoso) Then
                    obj_polizaendoso = Nothing
                End If
            End If
            polizaendoso = obj_polizaendoso
        End Get
        Set(ByVal value As cls_poliza_)
            obj_polizaendoso = value
        End Set
    End Property
    Property cliente As cls_cliente_
        Get
            If IsNothing(obj_cliente) Then
                obj_cliente = New cls_cliente_
                If Not obj_cliente.Buscar(idcliente) Then
                    obj_cliente = Nothing
                End If
            End If
            cliente = obj_cliente
        End Get
        Set(ByVal value As cls_cliente_)
            obj_cliente = value
        End Set
    End Property
    Property vendedor As cls_vendedor_
        Get
            If IsNothing(obj_vendedor) Then
                obj_vendedor = New cls_vendedor_
                If Not obj_vendedor.Buscar(idvendedor) Then
                    obj_vendedor = Nothing
                End If
            End If
            vendedor = obj_vendedor
        End Get
        Set(ByVal value As cls_vendedor_)
            obj_vendedor = value
        End Set
    End Property
    Property riesgo As cls_riesgo_
        Get
            If IsNothing(obj_riesgo) Then
                obj_riesgo = New cls_riesgo_
                If Not obj_riesgo.Buscar(idriesgo) Then
                    obj_riesgo = Nothing
                End If
            End If
            riesgo = obj_riesgo
        End Get
        Set(ByVal value As cls_riesgo_)
            obj_riesgo = value
        End Set
    End Property
    Property proveedor As cls_proveedor_
        Get
            If IsNothing(obj_proveedor) Then
                obj_proveedor = New cls_proveedor_
                If Not obj_proveedor.Buscar(idproveedor) Then
                    obj_proveedor = Nothing
                End If
            End If
            proveedor = obj_proveedor
        End Get
        Set(ByVal value As cls_proveedor_)
            obj_proveedor = value
        End Set
    End Property
    Property marca As cls_marca_
        Get
            If IsNothing(obj_marca) Then
                obj_marca = New cls_marca_
                If Not obj_marca.Buscar(idmarca) Then
                    obj_marca = Nothing
                End If
            End If
            marca = obj_marca
        End Get
        Set(ByVal value As cls_marca_)
            obj_marca = value
        End Set
    End Property
    Property modelo As cls_modelo_
        Get
            If IsNothing(obj_modelo) Then
                obj_modelo = New cls_modelo_
                If Not obj_modelo.Buscar(idmodelo) Then
                    obj_modelo = Nothing
                End If
            End If
            modelo = obj_modelo
        End Get
        Set(ByVal value As cls_modelo_)
            obj_modelo = value
        End Set
    End Property
    Property tipovencimiento As cls_tipovencimiento_
        Get
            If IsNothing(obj_tipovencimiento) Then
                obj_tipovencimiento = New cls_tipovencimiento_
                If Not obj_tipovencimiento.Buscar(idtipovencimiento) Then
                    obj_tipovencimiento = Nothing
                End If
            End If
            tipovencimiento = obj_tipovencimiento
        End Get
        Set(ByVal value As cls_tipovencimiento_)
            obj_tipovencimiento = value
        End Set
    End Property

    Property Items() As Collections.Generic.List(Of cls_poliza_)
        Get
            Items = col_Items
        End Get
        Set(ByVal value As Collections.Generic.List(Of cls_poliza_))
            col_Items = value
        End Set
    End Property
    Property cuota_() As cls_cuota_
        Get
            If IsNothing(obj_cuota_) Then
                obj_cuota_ = New cls_cuota_
                If Not obj_cuota_.CargarXidpoliza(idpoliza) Then
                    obj_cuota_ = Nothing
                End If
            End If
            cuota_ = obj_cuota_
        End Get
        Set(ByVal value As cls_cuota_)
            obj_cuota_ = value
        End Set
    End Property
    Property registro As cls_registro_
        Get
            If IsNothing(obj_registro) Then
                obj_registro = New cls_registro_
                If Not obj_registro.Buscar(idregistro) Then
                    obj_registro = Nothing
                End If
            End If
            registro = obj_registro
        End Get
        Set(ByVal value As cls_registro_)
            obj_registro = value
        End Set
    End Property
#End Region

    Private Sub CargarColeccion(ByVal obj_Reader As SqlDataReader)
        col_Items = New Collections.Generic.List(Of cls_poliza_)
        While obj_Reader.Read()
            Dim Elemento As New cls_poliza_
            Elemento.int_idpoliza = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idpoliza")))

            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("precotizacion"))) = False Then
                Elemento.bit_precotizacion = (obj_Reader.GetValue(obj_Reader.GetOrdinal("precotizacion")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("nueva"))) = False Then
                Elemento.bit_nueva = (obj_Reader.GetValue(obj_Reader.GetOrdinal("nueva")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("numero"))) = False Then
                Elemento.str_numero = (obj_Reader.GetValue(obj_Reader.GetOrdinal("numero")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("numerorenueva"))) = False Then
                Elemento.str_numerorenueva = (obj_Reader.GetValue(obj_Reader.GetOrdinal("numerorenueva")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idpolizarenueva"))) = False Then
                Elemento.int_idpolizarenueva = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idpolizarenueva")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("endoso"))) = False Then
                Elemento.bit_endoso = (obj_Reader.GetValue(obj_Reader.GetOrdinal("endoso")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idpolizaendoso"))) = False Then
                Elemento.int_idpolizaendoso = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idpolizaendoso")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("cambiounidad"))) = False Then
                Elemento.bit_cambiounidad = (obj_Reader.GetValue(obj_Reader.GetOrdinal("cambiounidad")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("vigenciadesde"))) = False Then
                Elemento.dte_vigenciadesde = (obj_Reader.GetValue(obj_Reader.GetOrdinal("vigenciadesde")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("vigenciahasta"))) = False Then
                Elemento.dte_vigenciahasta = (obj_Reader.GetValue(obj_Reader.GetOrdinal("vigenciahasta")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idcliente"))) = False Then
                Elemento.int_idcliente = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idcliente")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idriesgo"))) = False Then
                Elemento.int_idriesgo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idriesgo")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idproveedor"))) = False Then
                Elemento.int_idproveedor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idproveedor")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idmarca"))) = False Then
                Elemento.int_idmarca = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idmarca")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idmodelo"))) = False Then
                Elemento.int_idmodelo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idmodelo")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("año"))) = False Then
                Elemento.str_año = (obj_Reader.GetValue(obj_Reader.GetOrdinal("año")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("patente"))) = False Then
                Elemento.str_patente = (obj_Reader.GetValue(obj_Reader.GetOrdinal("patente")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("obs"))) = False Then
                Elemento.str_obs = (obj_Reader.GetValue(obj_Reader.GetOrdinal("obs")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("observaciones"))) = False Then
                Elemento.str_observaciones = (obj_Reader.GetValue(obj_Reader.GetOrdinal("observaciones")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("importe"))) = False Then
                Elemento.dbl_importe = (obj_Reader.GetValue(obj_Reader.GetOrdinal("importe")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("cuotas"))) = False Then
                Elemento.int_cuotas = (obj_Reader.GetValue(obj_Reader.GetOrdinal("cuotas")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("importecuota"))) = False Then
                Elemento.dbl_importecuota = (obj_Reader.GetValue(obj_Reader.GetOrdinal("importecuota")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idtipovencimiento"))) = False Then
                Elemento.int_idtipovencimiento = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idtipovencimiento")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("primervencimiento"))) = False Then
                Elemento.dte_primervencimiento = (obj_Reader.GetValue(obj_Reader.GetOrdinal("primervencimiento")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idregistro"))) = False Then
                Elemento.int_idregistro = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idregistro")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idvendedor"))) = False Then
                Elemento.int_idvendedor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idvendedor")))
            End If
            col_Items.Add(Elemento)
        End While
    End Sub

    Private Sub CargarVariables(ByVal obj_Reader As SqlDataReader)
        obj_Reader.Read()
        int_idpoliza = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idpoliza")))

        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("precotizacion"))) = False Then
            bit_precotizacion = (obj_Reader.GetValue(obj_Reader.GetOrdinal("precotizacion")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("nueva"))) = False Then
            bit_nueva = (obj_Reader.GetValue(obj_Reader.GetOrdinal("nueva")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("numero"))) = False Then
            str_numero = (obj_Reader.GetValue(obj_Reader.GetOrdinal("numero")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("numerorenueva"))) = False Then
            str_numerorenueva = (obj_Reader.GetValue(obj_Reader.GetOrdinal("numerorenueva")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idpolizarenueva"))) = False Then
            int_idpolizarenueva = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idpolizarenueva")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("endoso"))) = False Then
            bit_endoso = (obj_Reader.GetValue(obj_Reader.GetOrdinal("endoso")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idpolizaendoso"))) = False Then
            int_idpolizaendoso = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idpolizaendoso")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("cambiounidad"))) = False Then
            bit_cambiounidad = (obj_Reader.GetValue(obj_Reader.GetOrdinal("cambiounidad")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("vigenciadesde"))) = False Then
            dte_vigenciadesde = (obj_Reader.GetValue(obj_Reader.GetOrdinal("vigenciadesde")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("vigenciahasta"))) = False Then
            dte_vigenciahasta = (obj_Reader.GetValue(obj_Reader.GetOrdinal("vigenciahasta")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idcliente"))) = False Then
            int_idcliente = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idcliente")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idriesgo"))) = False Then
            int_idriesgo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idriesgo")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idproveedor"))) = False Then
            int_idproveedor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idproveedor")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idmarca"))) = False Then
            int_idmarca = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idmarca")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idmodelo"))) = False Then
            int_idmodelo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idmodelo")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("año"))) = False Then
            str_año = (obj_Reader.GetValue(obj_Reader.GetOrdinal("año")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("patente"))) = False Then
            str_patente = (obj_Reader.GetValue(obj_Reader.GetOrdinal("patente")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("obs"))) = False Then
            str_obs = (obj_Reader.GetValue(obj_Reader.GetOrdinal("obs")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("observaciones"))) = False Then
            str_observaciones = (obj_Reader.GetValue(obj_Reader.GetOrdinal("observaciones")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("importe"))) = False Then
            dbl_importe = (obj_Reader.GetValue(obj_Reader.GetOrdinal("importe")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("cuotas"))) = False Then
            int_cuotas = (obj_Reader.GetValue(obj_Reader.GetOrdinal("cuotas")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("importecuota"))) = False Then
            dbl_importecuota = (obj_Reader.GetValue(obj_Reader.GetOrdinal("importecuota")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idtipovencimiento"))) = False Then
            int_idtipovencimiento = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idtipovencimiento")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("primervencimiento"))) = False Then
            dte_primervencimiento = (obj_Reader.GetValue(obj_Reader.GetOrdinal("primervencimiento")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idregistro"))) = False Then
            int_idregistro = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idregistro")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idvendedor"))) = False Then
            int_idvendedor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idvendedor")))
        End If
    End Sub

    Public Sub Nuevo(Optional ByVal ObtenerID As Boolean = False)
        Dim obj_Conexion As New cls_Conexion
        Try

            'Creacion de registro----------------------------------------------------
            If IsNothing(obj_registro) Then
                registro = New cls_registro_
                registro.fechacreado = Now
                registro.idusuariocreado = UsuarioLOG.idusuario
                registro.fechamodificado = Now
                registro.idusuariomodificado = UsuarioLOG.idusuario
                registro.idregistroestado = 1
                registro.idusuarioregistroestado = UsuarioLOG.idusuario
                registro.Nuevo(True)
                idregistro = obj_registro.idregistro
            End If
            '------------------------------------------------------------------------

            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "poliza__Nuevo"
                .Parameters.Add("@precotizacion", SqlDbType.Bit).Value = bit_precotizacion
                .Parameters.Add("@nueva", SqlDbType.Bit).Value = bit_nueva
                .Parameters.Add("@numero", SqlDbType.NVarChar).Value = str_numero
                .Parameters.Add("@numerorenueva", SqlDbType.NVarChar).Value = str_numerorenueva
                .Parameters.Add("@idpolizarenueva", SqlDbType.Int).Value = int_idpolizarenueva
                .Parameters.Add("@endoso", SqlDbType.Bit).Value = bit_endoso
                .Parameters.Add("@idpolizaendoso", SqlDbType.Int).Value = int_idpolizaendoso
                .Parameters.Add("@cambiounidad", SqlDbType.Bit).Value = bit_cambiounidad
                .Parameters.Add("@vigenciadesde", SqlDbType.DateTime).Value = dte_vigenciadesde
                .Parameters.Add("@vigenciahasta", SqlDbType.DateTime).Value = dte_vigenciahasta
                .Parameters.Add("@idcliente", SqlDbType.Int).Value = int_idcliente
                .Parameters.Add("@idriesgo", SqlDbType.Int).Value = int_idriesgo
                .Parameters.Add("@idproveedor", SqlDbType.Int).Value = int_idproveedor
                .Parameters.Add("@idmarca", SqlDbType.Int).Value = int_idmarca
                .Parameters.Add("@idmodelo", SqlDbType.Int).Value = int_idmodelo
                .Parameters.Add("@año", SqlDbType.NVarChar).Value = str_año
                .Parameters.Add("@patente", SqlDbType.NVarChar).Value = str_patente
                .Parameters.Add("@obs", SqlDbType.NVarChar).Value = str_obs
                .Parameters.Add("@observaciones", SqlDbType.NVarChar).Value = str_observaciones
                .Parameters.Add("@importe", SqlDbType.Decimal).Value = dbl_importe
                .Parameters.Add("@cuotas", SqlDbType.Int).Value = int_cuotas
                .Parameters.Add("@importecuota", SqlDbType.Decimal).Value = dbl_importecuota
                .Parameters.Add("@idtipovencimiento", SqlDbType.Int).Value = int_idtipovencimiento
                .Parameters.Add("@primervencimiento", SqlDbType.DateTime).Value = dte_primervencimiento
                .Parameters.Add("@idregistro", SqlDbType.Int).Value = int_idregistro
                .Parameters.Add("@idvendedor", SqlDbType.Int).Value = int_idvendedor
                .ExecuteNonQuery()
            End With
                CargarUltimo()

            'Creacion de documentodetalle_--------------------------------------------------
            If Not IsNothing(cuota_) Then
                If Not IsNothing(cuota_.Items) Then
                    For Each cuota As cls_cuota_ In cuota_.Items
                        cuota.idpoliza = idpoliza
                        cuota.Nuevo(True)
                    Next
                End If
            End If
            '-------------------------------------------------------------------------

        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al Crear el registro de poliza_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Sub Modificar()
        Dim obj_Conexion As New cls_Conexion
        Try

            'Modificacion de registro------------------------------------------------
            registro.fechamodificado = Now : registro.idusuariomodificado = UsuarioLOG.idusuario
            registro.Modificar()
            '------------------------------------------------------------------------

            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "poliza__Modificar"
                .Parameters.Add("@idpoliza", SqlDbType.Int).Value = int_idpoliza
                .Parameters.Add("@precotizacion", SqlDbType.Bit).Value = bit_precotizacion
                .Parameters.Add("@nueva", SqlDbType.Bit).Value = bit_nueva
                .Parameters.Add("@numero", SqlDbType.NVarChar).Value = str_numero
                .Parameters.Add("@numerorenueva", SqlDbType.NVarChar).Value = str_numerorenueva
                .Parameters.Add("@idpolizarenueva", SqlDbType.Int).Value = int_idpolizarenueva
                .Parameters.Add("@endoso", SqlDbType.Bit).Value = bit_endoso
                .Parameters.Add("@idpolizaendoso", SqlDbType.Int).Value = int_idpolizaendoso
                .Parameters.Add("@cambiounidad", SqlDbType.Bit).Value = bit_cambiounidad
                .Parameters.Add("@vigenciadesde", SqlDbType.DateTime).Value = dte_vigenciadesde
                .Parameters.Add("@vigenciahasta", SqlDbType.DateTime).Value = dte_vigenciahasta
                .Parameters.Add("@idcliente", SqlDbType.Int).Value = int_idcliente
                .Parameters.Add("@idriesgo", SqlDbType.Int).Value = int_idriesgo
                .Parameters.Add("@idproveedor", SqlDbType.Int).Value = int_idproveedor
                .Parameters.Add("@idmarca", SqlDbType.Int).Value = int_idmarca
                .Parameters.Add("@idmodelo", SqlDbType.Int).Value = int_idmodelo
                .Parameters.Add("@año", SqlDbType.NVarChar).Value = str_año
                .Parameters.Add("@patente", SqlDbType.NVarChar).Value = str_patente
                .Parameters.Add("@obs", SqlDbType.NVarChar).Value = str_obs
                .Parameters.Add("@observaciones", SqlDbType.NVarChar).Value = str_observaciones
                .Parameters.Add("@importe", SqlDbType.Decimal).Value = dbl_importe
                .Parameters.Add("@cuotas", SqlDbType.Int).Value = int_cuotas
                .Parameters.Add("@importecuota", SqlDbType.Decimal).Value = dbl_importecuota
                .Parameters.Add("@idtipovencimiento", SqlDbType.Int).Value = int_idtipovencimiento
                .Parameters.Add("@primervencimiento", SqlDbType.DateTime).Value = dte_primervencimiento
                .Parameters.Add("@idregistro", SqlDbType.Int).Value = int_idregistro
                .Parameters.Add("@idvendedor", SqlDbType.Int).Value = int_idvendedor
                .ExecuteNonQuery()
            End With

            'Creacion/modificacion de cuotas-------------------------------------
            If Not IsNothing(cuota_) Then
                If Not IsNothing(cuota_.Items) Then
                    For Each cuota As cls_cuota_ In cuota_.Items
                        If cuota.idcuota = 0 Then
                            cuota.idpoliza = idpoliza
                            cuota.Nuevo(True)
                        Else
                            cuota.Modificar()
                        End If
                    Next
                End If
            End If
            '-------------------------------------------------------------------------


        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al Modificar el registro de poliza_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Sub Eliminar(ByVal idpoliza As Integer)
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "poliza__Eliminar"
                .Parameters.Add("@idpoliza", SqlDbType.int).Value = idpoliza
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al Eliminar el registro de poliza_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Function Buscar(ByVal idpoliza As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            Buscar = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "poliza__Buscar"
                .Parameters.Add("@idpoliza", SqlDbType.int).Value = idpoliza
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
                Buscar = True
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al Buscar el registro de poliza_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Sub CargarUltimo()
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "poliza__CargarUltimo"
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al CargarUltimo registro de poliza_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Sub

    Public Function CargarTodos(Optional ByVal idregistroestado As Integer = 1) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarTodos = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "poliza__CargarTodos"
                .Parameters.Add("@idregistroestado", SqlDbType.Int).Value = idregistroestado
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarTodos = True
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al CargarTodos los registros de poliza_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function
    Public Function CargarXvigencia(ByRef desde As DateTime, ByRef hasta As DateTime) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarXvigencia = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "poliza__CargarXvigencia"
                .Parameters.Add("@desde", SqlDbType.DateTime).Value = desde
                .Parameters.Add("@hasta", SqlDbType.DateTime).Value = hasta
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarXvigencia = True
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al CargarXvigencia los registros de poliza_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function
    Public Function CargarXnumero(ByRef numero As String) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarXnumero = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "poliza__CargarXnumero"
                .Parameters.Add("@numero", SqlDbType.NVarChar).Value = numero
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarXnumero = True
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al CargarXnumero los registros de poliza_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim obj_poliza_Clon As New cls_poliza_
        obj_poliza_Clon.int_idpoliza = Me.int_idpoliza
        obj_poliza_Clon.bit_precotizacion = Me.bit_precotizacion
        obj_poliza_Clon.bit_nueva = Me.bit_nueva
        obj_poliza_Clon.str_numero = Me.str_numero
        obj_poliza_Clon.str_numerorenueva = Me.str_numerorenueva
        obj_poliza_Clon.int_idpolizarenueva = Me.int_idpolizarenueva
        obj_poliza_Clon.bit_endoso = Me.bit_endoso
        obj_poliza_Clon.int_idpolizaendoso = Me.int_idpolizaendoso
        obj_poliza_Clon.bit_cambiounidad = Me.bit_cambiounidad
        obj_poliza_Clon.dte_vigenciadesde = Me.dte_vigenciadesde
        obj_poliza_Clon.dte_vigenciahasta = Me.dte_vigenciahasta
        obj_poliza_Clon.int_idcliente = Me.int_idcliente
        obj_poliza_Clon.int_idriesgo = Me.int_idriesgo
        obj_poliza_Clon.int_idproveedor = Me.int_idproveedor
        obj_poliza_Clon.int_idmarca = Me.int_idmarca
        obj_poliza_Clon.int_idmodelo = Me.int_idmodelo
        obj_poliza_Clon.str_año = Me.str_año
        obj_poliza_Clon.str_patente = Me.str_patente
        obj_poliza_Clon.str_obs = Me.str_obs
        obj_poliza_Clon.str_observaciones = Me.str_observaciones
        obj_poliza_Clon.dbl_importe = Me.dbl_importe
        obj_poliza_Clon.int_cuotas = Me.int_cuotas
        obj_poliza_Clon.dbl_importecuota = Me.dbl_importecuota
        obj_poliza_Clon.int_idtipovencimiento = Me.int_idtipovencimiento
        obj_poliza_Clon.dte_primervencimiento = Me.dte_primervencimiento
        obj_poliza_Clon.int_idregistro = Me.int_idregistro
        obj_poliza_Clon.int_idvendedor = Me.int_idvendedor
        obj_poliza_Clon.col_Items = Me.col_Items
        Return obj_poliza_Clon
    End Function

End Class
